﻿/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xoskit.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#ifndef __A2E0ECAA_8AAF_4A02_9AAF_35B7FF9A2867__
#define __A2E0ECAA_8AAF_4A02_9AAF_35B7FF9A2867__

// DRIVER={MySQL ODBC 5.3 ANSI Driver};SERVER=192.168.80.131;PORT=3306;DATABASE=javadb;UID=root;PWD=root;CharSet=UTF8;

namespace xos_odbc
{
    class i_fields;
    class i_stmt;

    /////////////////////////////////////////////////////////////////////////////////
    // 
    // 数连接接口
    // 
    class i_dbc : public xos::i_release
    {
    public:
        virtual ~i_dbc(){}

    public:
		// 
		// 得到最近的错误信息
		// 
		virtual int get_last_err_info( char * lpszInfo, int nSize, int * lpnInfoLen, int * lpnLenNeeded ) = 0;

        // 
        // 利用不同数据库的功能生成对应sql放在lpszSql中，得到最后新增记录的自增ID。
        // 成功返回0,结果在lpIntId中
        // 需要在设置异步前执行
        // 
        virtual int get_last_insert_id( const char * lpszSql, int * lpIntId ) = 0;

        // 
        // 直接运行sql
        // 
        virtual int execute_direct( const char * lpszSql, i_stmt ** ppStmt ) = 0;

        // 
        // 编译sql
        // 
        virtual int prepare_sql( const char * lpszSql, i_stmt ** ppStmt ) = 0;

        // 
        // 生成i_fields
        // 
        virtual int create_fields( i_fields ** ppv ) = 0;

        // 
        // 创建一个htmt
        // 
        virtual int create_stmt( i_stmt ** ppv ) = 0;

        // 
        // 设置是否异步执行sql
        // 
        virtual int async_test( bool * bAsyncCon, bool * bAsyncStmt ) = 0;
        virtual int set_connect_fun_async( bool bAsync ) = 0;
        virtual int set_async( bool bAsync ) = 0;

        // 
        //  0 : success. 
        //  1 : running. 
        // -1 : failed
        // 
		virtual int end_trans( bool bSuccess ) = 0;

        // 
        //  0 : success. 
        //  1 : running. 
        // -1 : failed
        // 
		virtual int begin_trans() = 0;

        // 
        //  0 : success. 
        //  1 : running. 
        // -1 : failed
        // 
        virtual int connect() = 0;
    };

} // xos_odbc

#endif // __A2E0ECAA_8AAF_4A02_9AAF_35B7FF9A2867__
